﻿/// <reference path="worm.js" />
/// <reference path="application.js" />

function Controller(worm) {
    this.isActive = false;
    this.worm = worm;

    if (typeof Controller.initialized == "undefined") {

        Controller.prototype.Think = function () {
            if (this.worm != null && this.isActive) {
                if (app.input.key.isLeftKeyPressed) {
                    this.worm.GoLeft();
                }
                if (app.input.key.isRightKeyPressed) {
                    this.worm.GoRight();
                }
                if (app.input.key.isJumpKeyPressed) {
                    this.worm.Jump();
                }
                if (app.input.key.isViewFinderUpKeyPressed) {
                    this.worm.ViewFinderUp();
                }
                if (app.input.key.isViewFinderDownKeyPressed) {
                    this.worm.ViewFinderDown();
                }
                if (app.input.key.isCameraTrackKeyPressed) {
                    app.data.camera.Track(this.worm);
                }
                if (app.input.key.isCameraDownKeyPressed) {
                    app.data.camera.GoDown();
                }
                if (app.input.key.isCameraUpKeyPressed) {
                    app.data.camera.GoUp();
                }
                if (app.input.key.isCameraLeftKeyPressed) {
                    app.data.camera.GoLeft();
                }
                if (app.input.key.isCameraRightKeyPressed) {
                    app.data.camera.GoRight();
                }
                if (app.input.key.isToggleRopeKeyPressed == true) {
                    app.input.key.isToggleRopeKeyPressed = "done";
                    this.worm.ToggleRope();
                }
            }
        };

        Controller.initialized = true;
    }
};